package cqrtplm.controller;

import com.hustcad.plm.pdm.partbom.vo.PdmPartInfoVO;
import com.ty.basic.constant.ApiPathConstant;
import com.ty.basic.response.ResponseResult;
import cqrtplm.constant.RTErrorCodeEnum;
import cqrtplm.dto.ImportClassificationDTO;
import cqrtplm.service.HistoryDataImportService;
import cqrtplm.service.RTClassificationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping(ApiPathConstant.PRODUCT_VERSION_ONE_PATH + "history/")
@Api(tags = "历史数据导入")
public class HistoryDataImportController {
    @Resource
    private HistoryDataImportService historyDataImportService;
    @Resource
    private RTClassificationService classificationService;

    //导入工艺
    @PostMapping("importDoc")
    @ApiOperation("通用文档导入接口")
    public ResponseResult importDoc(MultipartFile file) {
        historyDataImportService.importDoc(file);
        return ResponseResult.success();
    }

    //导入图样代号
    @RequestMapping("importPatternCode")
    public ResponseResult importPatternCode(MultipartFile  file) {
        historyDataImportService.importPatternCode(file);
        return ResponseResult.success();
    }

    /**
     * 导入属性卡片
     * @return
     * @throws Exception
     */
    @PostMapping("/importAttributeCard")
    public ResponseResult importClassification(@ModelAttribute ImportClassificationDTO importClassificationDTO) throws Exception {
        classificationService.importClassification(importClassificationDTO);
        return ResponseResult.success();
    }

    @PostMapping("/importAttributeCard2")
    public ResponseResult importClassification2(MultipartFile  file) throws Exception {
        historyDataImportService.importClassification(file);
        return ResponseResult.success();
    }

    //导入标准件
    @RequestMapping("importStandardPart")
    public ResponseResult importStandardPart(MultipartFile  file) {
        List<PdmPartInfoVO> list = historyDataImportService.importStandardPart(file);
        return ResponseResult.success(list);
    }

    //导入专用件
    @RequestMapping("importSpecialPart")
    public ResponseResult importSpecialPart(MultipartFile  file) {
        List<PdmPartInfoVO> list = historyDataImportService.importSpecialPart(file);
        return ResponseResult.success(list);
    }

    //导入EBOM号历史数据
    @RequestMapping("importEbomHistoryData")
    public ResponseResult importEbomHistoryData(MultipartFile  file) {
        historyDataImportService.importEbomHistoryData(file);
        return ResponseResult.success();
    }

    /**
     * 导入三位数模
     * @param file
     * @return
     */
    @RequestMapping("import3DDigitalModel")
    public ResponseResult import3DDigitalModel(MultipartFile  file) {
        List<PdmPartInfoVO> list = historyDataImportService.import3DDigitalModel(file);
        return ResponseResult.success(list);
    }

    @RequestMapping("batchImportBom")
    public ResponseResult batchImportBom(MultipartFile file, HttpServletResponse response) {
        historyDataImportService.batchImportBom(file,response);
        return ResponseResult.success();
    }

    @PostMapping("importProcessDoc")
    @ApiOperation("工艺文件导入接口")
    public ResponseResult importProcessDoc(MultipartFile file) {
        try {
            historyDataImportService.importProcessDoc(file);
        } catch (Exception e) {
            e.printStackTrace();
            throw RTErrorCodeEnum.EXCEL_IMPORT_EXCEPTION.getException(e.getMessage());
        }
        return ResponseResult.success();
    }

    @GetMapping("downloadTemplate")
    public void downloadTemplate(HttpServletResponse response, @Param("fileName") String fileName) {
        historyDataImportService.downloadTemplate(response, fileName);
    }

    @PostMapping("updateDescribeRule")
    public ResponseResult updateDescribeRule(MultipartFile file) {
        historyDataImportService.batchUpdateDescribeRule(file);
        return ResponseResult.success();
    }

    @PostMapping("batchCreateAttribute")
    public ResponseResult batchCreateAttribute(MultipartFile file) {
        historyDataImportService.batchCreateAttribute(file);
        return ResponseResult.success();
    }

    @PostMapping("updateEnum")
    public ResponseResult updateEnum(MultipartFile file) {
        historyDataImportService.updateStandPartEnum(file);
        return ResponseResult.success();
    }

    @PostMapping("importPartPresentation")
    public ResponseResult importPartPresentation(MultipartFile file) {
        historyDataImportService.importPartPresentation(file,0);
        return ResponseResult.success();
    }
}

